<template>
  <div>
    <QueryForm
      v-model="filters"
      :query-form-config="queryFormConfig"
      @handleQuery="getList(1)"
      @clear="clear"
    />
    <el-table
      ref="table"
      v-loading="listLoading"
      :data="list"
      element-loading-text="Loading"
      border
      fit
      :header-row-class-name="'table-header'"
      class="doumee-element-table doumee-element-tableb"
    >
      <el-table-column
        align="center"
        :label="$t('message.txdh')"
        prop="id"
        show-overflow-tooltip
        min-width="280"
      />
      <el-table-column :label="$t('message.memberInfo')" min-width="250" align="center" show-overflow-tooltip>
        <template slot-scope="scope">
          {{ scope.row.nickName || '' }} {{ scope.row.phone || scope.row.memberCard ?'-':'' }}{{ scope.row.phone|| '' }}{{ scope.row.phone && scope.row.memberCard ?'-':'' }}{{ scope.row.memberCard || '' }}
        </template>
      </el-table-column>
      <el-table-column
        align="center"
        :label="$t('message.txje')"
        prop="amount"
        min-width="90"
        show-overflow-tooltip
      />
      <el-table-column
        align="center"
        :label="$t('message.txzsje')"
        prop="giveAmount"
        min-width="110"
        show-overflow-tooltip
      />
      <el-table-column :label="$t('message.txfs')" prop="wayType" min-width="90" align="center">
        <template slot-scope="scope">
          {{
            scope.row.wayType == 0
              ? $t('message.wx')
              : scope.row.wayType == 1
                ? $t('message.zfb')
                : scope.row.wayType == 2
                  ? $t('message.xj')
                  : ''
          }}
        </template>
      </el-table-column>
      <el-table-column
        align="center"
        :label="$t('message.czsj')"
        prop="createTime"
        show-overflow-tooltip
        min-width="160"
      />
      <el-table-column
        align="center"
        :label="$t('message.czy')"
        prop="creatorName"
        show-overflow-tooltip
        min-width="120"
      />
      <el-table-column
        align="center"
        :label="$t('message.fkcgsj')"
        prop="payTime"
        show-overflow-tooltip
        min-width="160"
      />
      <el-table-column
        align="center"
        :label="$t('message.sbm')"
        prop="code"
        min-width="260"
        show-overflow-tooltip
      />
      <el-table-column
        align="center"
        :label="$t('message.sbyy')"
        prop="msg"
        show-overflow-tooltip
        min-width="140"
      />
      <el-table-column
        :label="$t('message.bz')"
        show-overflow-tooltip
        prop="note"
        min-width="120"
        align="center"
      />
      <el-table-column :label="$t('message.status')" prop="status" min-width="100" align="center" fixed="right">
        <template slot-scope="scope">
          {{
            scope.row.status == 0
              ? $t('message.clz')
              : scope.row.status == 1
                ? $t('message.success')
                : scope.row.status == 2
                  ? $t('message.error')
                  : ''
          }}
        </template>
      </el-table-column>
      <el-table-column
        :label="$t('message.caozuo')"
        min-width="140"
        align="center"
        fixed="right"
      >
        <template slot-scope="scope">
          <div class="flex-cc">
            <el-button v-if="scope.row.status == 0 && meta.indexOf('MemberWithdrawalOperation') > -1" v-preventReClick type="text" @click="updateStatus(scope.row.id,0)">{{ $t('message.tk') }}</el-button>
            <el-button v-if="scope.row.status == 0 && meta.indexOf('MemberWithdrawalOperation') > -1" v-preventReClick type="text" @click="updateStatus(scope.row.id,1)">{{ $t('message.success') }}</el-button>
            <div v-if="scope.row.status != 0">-</div>
          </div>
        </template>
      </el-table-column>
    </el-table>
    <Paginations
      :total="total"
      :page="pagination.page"
      @current-change="getList"
      @SizeChange="handleSizeChange"
    />
  </div>
</template>

<script>
import { memberWithdrawalRecord, memberWithdrawalFailed } from '@/api'
import { parseTime } from '@/utils/index'
import QueryForm from '@/components/QueryForm'
import { queryFormConfig } from './config'
export default {
  name: 'WithDrawRecord',
  components: {
    QueryForm
  },
  data() {
    return {
      queryFormConfig,
      list: [],
      meta: [],
      listLoading: true,
      pagination: {
        page: 1,
        rows: 10,
        firstQueryTime: ''
      },
      total: 0,
      filters: {}
    }
  },
  created() {
    this.meta = this.$route.meta.buttons || []
    this.getList(1)
  },
  mounted() {
    this.$refs.table.doLayout()
  },
  methods: {
    handleSizeChange(value) {
      this.pagination.rows = value
      this.getList(1)
    },
    // 获取列表
    getList(page) {
      const { pagination, filters } = this
      if (page) {
        pagination.page = page
        this.pagination.page = page
      }
      pagination.firstQueryTime = parseTime(new Date())
      this.listLoading = true
      memberWithdrawalRecord({
        pagination,
        param: {
          venueId: sessionStorage.getItem('venueId'),
          startTime: filters.time && filters.time.length > 0 ? filters.time[0] : null,
          endTime: filters.time && filters.time.length > 0 ? filters.time[1] : null,
          ...filters
        }
      })
        .then((res) => {
          this.listLoading = false
          if (res.errorCode !== '000000') return
          this.list = res.recordList
          this.total = res.totalCount
        })
        .catch(() => {
          this.listLoading = false
        })
    },
    toDetail(id) {
      // console.log(id)
      this.$router.push({
        name: 'NoticeDetail',
        query: {
          id
        }
      })
    },
    // 清空
    clear() {
      this.filters = {}
      this.getList(1)
    },
    updateStatus(id, status) {
      let str = ''
      if (status === 1) {
        str = this.$t('message.cgqrtc')
      } else {
        str = this.$t('message.tktc')
      }
      this.$confirm(str, this.$t('message.ts'), {
        confirmButtonText: this.$t('message.qd'),
        cancelButtonText: this.$t('message.qx'),
        type: 'warning'
      }).then(() => {
        memberWithdrawalFailed({ param: { id, status }})
          .then(res => {
            if (res.errorCode === '000000') {
              if (status === 1) {
                this.$message.success(this.$t('message.czcg'))
              } else {
                this.$message.success(this.$t('message.tktcqr'))
              }
              this.getList()
            }
          })
      })
    }
  }
}
</script>

<style lang="scss" scoped>
.vip-info {
  display: flex;
  justify-content: center;
  .name-phone {
    flex: 1;
    display: flex;
    flex-direction: column;
    justify-content: space-between;
    text-align: left;
    margin-left: 10px;
  }
}
.viplist-entitycard-style {
  width: 50%;
}
.viplist-btn-style {
  margin-left: 20px;
}
.tableClass .cell {
  padding: 0 !important;
  height: 40px;
  line-height: 30px !important;
  text-align: center;
}
</style>
